package com.back.controller;


import com.back.model.dto.messages.MessagesDTO;
import com.back.model.dto.taskInfo.TaskInfoAddDTO;
import com.back.model.dto.taskInfo.TaskInfoQueryDTO;
import com.back.model.entity.TaskInfo;
import com.back.model.reslut.PageData;
import com.back.model.reslut.Result;
import com.back.model.vo.TaskInfoVO;
import com.back.model.vo.UserVO;
import com.back.service.TaskInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/task")
public class TaskInfoController {

    @Resource
    private TaskInfoService taskInfoService;


    // 创建任务(用户)
    @PostMapping("/create")
    public Result<Boolean> createTask(TaskInfoAddDTO taskInfoAddDTO) {
        TaskInfo taskInfo = new TaskInfo();
        BeanUtils.copyProperties(taskInfoAddDTO, taskInfo);
        return taskInfoService.createTask(taskInfo) ? Result.success() : Result.faile("创建失败");
    }


    // 关闭任务
    @GetMapping("/close")
    public Result<Boolean> closeTask(Integer id) {
        return taskInfoService.closeTask(id) ? Result.success() : Result.faile("创建失败");
    }


    // 删除任务
    @GetMapping("/delete")
    public Result<Boolean> deleteTask(Integer id) {
        return taskInfoService.deleteTask(id) ? Result.success() : Result.faile("创建失败");
    }


    // 获取任务列表
    @GetMapping("/list")
    public Result<Object> getTaskList(TaskInfoQueryDTO taskInfoQueryDTO) {
        PageData<TaskInfoVO> pageUser = taskInfoService.taskList(taskInfoQueryDTO);
        return Result.successData(pageUser);
    }

    @GetMapping("/taskInfo")
    public Result<TaskInfoVO> taskInfo(TaskInfoQueryDTO taskInfoQueryDTO) {
        TaskInfoVO pageUser = taskInfoService.taskInfo(taskInfoQueryDTO);
        return Result.successData(pageUser);
    }




    @PostMapping("/sendMessage")
    public Result<TaskInfoVO> sendMessage(MessagesDTO messagesDTO) {
        TaskInfoVO pageUser = taskInfoService.SendMessage(messagesDTO);
        return Result.successData(pageUser);
    }

}
